package com.whjz.dcfs.file.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.whjz.dcfs.file.model.FileInfo;
import com.whjz.dcfs.file.model.PageBean;

@Repository
public class FileDaoImpl implements FileDao {
	@Autowired
	private SqlMapClient sqlMapClient;

	public void saveFile(FileInfo file) throws SQLException {
		sqlMapClient.insert("insertFile", file);
	}

	public PageBean<FileInfo> selectFileInfo(Map map)
			throws SQLException {
		List<FileInfo> datas=  sqlMapClient.queryForList("getPageFileByCond", map);
		PageBean<FileInfo> pageBean = new PageBean<FileInfo>();
		pageBean.setList(datas);
		int total = (Integer)sqlMapClient.queryForObject("queryFileInfoCount", map);
		pageBean.setTotal(total);
		return pageBean;
	}

	public void removeFile(String fileId) throws SQLException {
		sqlMapClient.delete("deleteFile", fileId);
	}
	public String findNameByUserId(String userId) throws SQLException {
		 return sqlMapClient.queryForObject("findNameByUserId",userId).toString();
	}
	public List<FileInfo> selectFileInfoByCond(Map map) throws SQLException {
		List<FileInfo> datas=  sqlMapClient.queryForList("getFileByCond", map);
		return datas;
	}
}
